/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Solicitudes.java
 *
 * Created on 27/02/2012, 03:31:33 PM
 */

package sst.Vistas;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author alberto
 */
public class Solicitudes extends javax.swing.JDialog {
  public static DefaultTableModel modelo = new DefaultTableModel();
    //filas
    Object[] filas;
BuscaCliente.seleccion seleccion;
    /** Creates new form Solicitudes */
    public Solicitudes(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);

         try{
           // Conectar a mysql:
             Class.forName("com.mysql.jdbc.Driver");
             Connection conne=(Connection) DriverManager.getConnection("jdbc:mysql://localhost/sst","root","alberto.1990");
           // creo la consulta sql:
             Statement consulta=(Statement) conne.createStatement();                         //textField de busqueda
             java.sql.ResultSet rs = consulta.executeQuery("SELECT cliente.nombreCliente, solicitud.descripcion, tecnico.nombreCompleto, tipoSolicitud.nombreSolicitud, solicitud.observacion, estadoSolicitud.estadoSolicitud FROM cliente, solicitud, tecnico, estadoSolicitud, tipoSolicitud WHERE (solicitud.estadoSolicitud = 0 OR solicitud.estadoSolicitud=1 OR solicitud.estadoSolicitud = 3) and cliente.rif=solicitud.clienteRif and estadoSolicitud.idestadoSolicitud = solicitud.estadoSolicitud and tipoSolicitud.idtipoSolicitud = solicitud.tipoSolicitud and tecnico.cedula = solicitud.cedulaTecnico");
            // reasigno un modelo en blanco:
                 modelo = new DefaultTableModel();
                 jtResultado.setModel(modelo);


            //creamos la columnas de nuestra tabla:
                 modelo.addColumn("Cliente");
                 modelo.addColumn("Descripcion");
                 modelo.addColumn("Tecnico a cargo");
                 modelo.addColumn("Tipo Solicitud");
                 modelo.addColumn("Observacion");
                 modelo.addColumn("Estado Solicitud");

            //asigno el tamaño del arreglo co la cantidad de columnas:
                 filas = new Object[modelo.getColumnCount()];
            //escribo las filas:
            while (rs.next())
            {                   //cantidad de columnas
                 for (int i=0;i<modelo.getColumnCount();i++){
                  filas[i] = rs.getObject(i+1);
                 }
                 //escribo las filas del resultado SQL//
                 modelo.addRow(filas);
                 jtResultado.setModel(modelo);


            }
              //error de lectura a los campos de la bd
              } catch(SQLException e){
            JOptionPane.showMessageDialog(null,"Error sql no se pueden leer datos");
          //error desconocido //por lo general no hay conexion con la base de datos
        } catch(ClassNotFoundException e){
            JOptionPane.showMessageDialog(null,"Error al leer la base de datos");

        }


    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jtResultado = new javax.swing.JTable();
        botonVerReporte = new javax.swing.JButton();
        botonModificar = new javax.swing.JButton();
        botonCerrar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        jtResultado.setAutoCreateRowSorter(true);
        jtResultado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jtResultado.getTableHeader().setReorderingAllowed(false);
        jtResultado.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtResultadoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtResultado);

        botonVerReporte.setText("Visualizar Solicitud");
        botonVerReporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonVerReporteActionPerformed(evt);
            }
        });

        botonModificar.setText("Modificar Solicitud");
        botonModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonModificarActionPerformed(evt);
            }
        });

        botonCerrar.setText("Cerrar Ventana");
        botonCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCerrarActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 3, 18)); // NOI18N
        jLabel1.setText("Lista de Solicitudes Activas");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(botonVerReporte, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(botonModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addComponent(botonCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 833, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 355, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonVerReporte)
                    .addComponent(botonCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonModificar))
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(50, 50, 50)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(56, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtResultadoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtResultadoMouseClicked

}//GEN-LAST:event_jtResultadoMouseClicked

    private void botonVerReporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonVerReporteActionPerformed
        // Reporte individual de la solcitud
    }//GEN-LAST:event_botonVerReporteActionPerformed

    private void botonModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonModificarActionPerformed
        
    }//GEN-LAST:event_botonModificarActionPerformed

    private void botonCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCerrarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_botonCerrarActionPerformed

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
      
         
         
    }//GEN-LAST:event_formKeyPressed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Solicitudes dialog = new Solicitudes(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonCerrar;
    private javax.swing.JButton botonModificar;
    private javax.swing.JButton botonVerReporte;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jtResultado;
    // End of variables declaration//GEN-END:variables

}
